import { createRouter, createWebHistory } from 'vue-router';
import HomePage from '../pages/HomePage.vue';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomePage
    },
    // 重定向到首页
    {
      path: '/:pathMatch(.*)*',
      redirect: '/'
    },
    // 在现有路由配置中添加
    {
      path: '/ai',
      name: 'AI',
      beforeEnter: () => {
        // 跳转到辰晓AI应用
        window.location.href = 'http://localhost:3001/';
      }
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  }
});

export default router;